﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AAA.Logger;
using System.IO;

namespace AAA.Trade
{
    public class TradeLogger : AAA.Logger.Logger
    {
        private string _strFilename;
        public TradeLogger(string strFilename)
        {
            _strFilename = strFilename;
            OnLoggableEvent += new LoggableEventHandler(LogMessage);
        }

        public void LogMessage(object o, LogInfoEventArgs e)
        {
            StreamWriter sw = new StreamWriter(_strFilename, true, Encoding.Default);
            try
            {
                sw.WriteLine("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]-I-" + e.Message);
            }
            catch (Exception ex)
            {
                try
                {
                    sw.WriteLine("[" + DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss") + "]-E-" + ex.Message + "," + ex.StackTrace);
                }
                catch { }
            }
            finally
            {
                if (sw != null)
                    sw.Close();
            }
        }
    }
}
